package com.excuse.excusebuilder.view.activity;

import android.support.v7.widget.Toolbar;
import android.widget.Button;
import android.widget.EditText;

import com.excuse.excusebuilder.R;
import com.excuse.excusebuilder.base.BaseActivity;
import com.excuse.excusebuilder.commen.util.NetWorkUtil;
import com.excuse.excusebuilder.commen.util.ToastUtil;
import com.excuse.excusebuilder.impl.view.AddPostFragmentInterface;
import com.excuse.excusebuilder.presenter.AddPostPresenter;

import butterknife.BindView;
import butterknife.OnClick;
import cn.bmob.v3.BmobUser;

/**
 * Created by U-nookia on 2017/4/18.
 */

public class AddPostActivity extends BaseActivity implements AddPostFragmentInterface{

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.add_post_title)
    EditText addPostTitle;
    @BindView(R.id.add_post_content)
    EditText addPostContent;
    @BindView(R.id.add_post_btn)
    Button addPostBtn;

    private AddPostPresenter presenter;

    @Override
    protected void initData() {
        presenter = new AddPostPresenter(context,this);
        initToolbar();
        initBt();
    }

    private void initBt() {
        addPostBtn.setBackgroundResource(R.color.md_grey_200);
    }

    private void initToolbar() {
        toolbar.setTitle("发布帖子");
        toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000));
    }

    @Override
    public int getLayoutResId() {
        return R.layout.activity_add_post;
    }

    @OnClick(R.id.add_post_btn)
    public void onViewClicked() {
        String title = addPostTitle.getText().toString();
        String content = addPostContent.getText().toString();
        if ("".equals(title)||"".equals(content)){
            ToastUtil.makeShortToast(context,"输入内容不能为空");
            return;
        }
        if (!NetWorkUtil.netWorkConnected){
            ToastUtil.makeShortToast(context,"请检查网络");
            return;
        }
        if (BmobUser.getCurrentUser()==null){
            ToastUtil.makeShortToast(context,"请先登录");
            return;
        }
        presenter.savePostToBmob(title,content);
    }

    @Override
    public void finishView() {
        finish();
    }
}
